<template>
	<u-count-down :time="countTimer" :format="timeFormat" autoStart :millisecond="isShowMs" @change="onChange">
		<view :class="['time', styleType === 'default' ? '' : 'time--setting']">
			<view class="time__custom" v-if="isShowHours">
				<text class="time__custom__item">{{ timeData.hours | timeFormat}}</text>
				<!-- <text class="time__doc">:</text> -->
			</view>
			<text class="time__doc" v-if="isShowHours">:</text>
			<view class="time__custom">
				<text class="time__custom__item">{{ timeData.minutes | timeFormat}}</text>
			</view>
			<text class="time__doc">:</text>
			<view class="time__custom">
				<text class="time__custom__item">{{ timeData.seconds | timeFormat}}</text>
			</view>
			<template v-if="isShowMs">
				<text class="time__doc">:</text>
				<view class="time__custom">
					<text class="time__custom__item">{{ timeData.milliseconds | msFormat}}</text>
				</view>
			</template>
			
		</view>
	</u-count-down>
</template>

<script>
	export default {
		data() {
			return {
				timeData: {},
			}
		},
		props:{
			styleType:{
				type:String,
				default:"default"
			},
			countTimer:{
				type:Number,
				default:0
			},
			isShowHours:{ //是否显示小时
				type:Boolean,
				default:true
			},
			isShowMs:{ //是否显示毫秒
				type:Boolean,
				default:false
			}
		},
		computed:{
			timeFormat(){
				let res = this.isShowMs ? "HH:mm:ss:SSS" : "HH:mm:ss"
				return res
			}
		},
		filters:{
			timeFormat(value){
				return value >= 10 ? value : "0" +value
			},
			msFormat(value){
				return value >= 100 ? Math.round(value / 10) : value
			}
		},
		methods: {
			// 时间改变
			onChange(e) {
				this.timeData = e
			}
		}
	}
</script>

<style lang="scss" scoped>
	.time {
		@include flexRowAlign();
		&__custom {
			margin-top: 4px;
			width: 56rpx;
			height: 60rpx;
			background-color: #1a8ee9;
			border-radius: 8rpx;
			@include flexCenter();
			&__item {
				color: #fff;
				font-size: 26rpx;
				text-align: center;
			}
		}
		&__doc {
			color: #1a8ee9;
			padding: 0px 8rpx;
		}
	}
	.time--setting{
		margin-left: 12rpx;
		.time__custom{
			width: 40rpx;
			height: 40rpx;
			background-color: #e54635;
			&__item {
				color: #fff;
				font-size: 24rpx;
				text-align: center;
			}
		}
		.time__doc {
			color: #e54635;
			font-size: 20rpx;
			padding: 0px 8rpx;
		}
	}
</style>
